import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    rediect:'/home'
  },
  {
    path:'/home',
    name:'home',
    component:HomeView,
    redirect:'/home/index',
    children:[
      {
        path:'index',
        name:'index',
        component:() => import('@/views/Index.vue'),
        meta:{
          title:'美团 - 首页'
        }
      },
      {
        path:'shop',
        name:'shop',
        component:() => import('@/views/Shop.vue'),
        meta:{
          title:'美团 - 美团电商'
        }
      },
      {
        path:'message',
        name:'message',
        component:() => import('@/views/Message.vue'),
        meta:{
          title:'美团 - 消息页'
        }
      },
      {
        path:'shopcar',
        name:'shopcar',
        component:() => import('@/views/Shopcar.vue'),
        meta:{
          title:'美团 - 我的购物车'
        }
      },
      {
        path:'me',
        name:'me',
        component:()=>import('@/views/Me.vue'),
        meta:{
          title:'美团 - 我的个人中心'
        }
      }
    ]
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to,from,next)=> {
  document.title = to.meta.title
  next()
})
export default router
